<template>
  <div class="prepare">
    <van-cell-group>
      <van-cell>
        <div class="van-cell-title">
          <span class="van-cell-text">收件人</span>
          <span class="van-cell-text">151****9779</span>
          <van-tag type="danger">默认</van-tag>
        </div>
        <div class="van-cell-detail">
          <transition appear appear-class="apper" appear-active-class="apper-active">
            <span class="marquee">山东省 济南市 历下区 奥体西路与工业南路交西路与工业汇处北汇处北800米</span>
          </transition>
        </div>
        <van-icon slot="right-icon" name="arrow" class="van-cell__right-icon" />
      </van-cell>
    </van-cell-group>

    <van-panel title="订单号：51a5sa24ew1ew2ew1g" status="交易成功" class="order-panel">
      <van-card :title="goods.title" :desc="formatPrice()" :num="goods.num" :thumb="goods.thumb" />
      <div slot="footer" class="test">
        您可以去“<a>我的物品</a>”中查看兑 换的内容
      </div>
    </van-panel>

    <van-submit-bar button-text="查看" button-type="default" class="order-action">
      <div slot="default" class="order-amount">
        实付：<span class="price">{{goods.price}}</span><small>橙子</small>
      </div>
    </van-submit-bar>
  </div>
</template>
<script>
import {
  Tag,
  Col,
  Icon,
  Cell,
  CellGroup,
  Card,
  Button,
  Panel,
  NoticeBar,
  SubmitBar
} from 'vant'

export default {
  components: {
    [Tag.name]: Tag,
    [Col.name]: Col,
    [Icon.name]: Icon,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Panel.name]: Panel,
    [Card.name]: Card,
    [Button.name]: Button,
    [NoticeBar.name]: NoticeBar,
    [SubmitBar.name]: SubmitBar
  },
  data () {
    return {
      goods: {
        id: 1,
        title: '美国伽力果（约680g/3个）',
        price: 2680,
        express: '免运费',
        description: '简介',
        remain: 19,
        num: 1,
        material: true,
        content:
          '<h1>商品简介</h1>djdslkfkfdkjldsflkjsdskjldfskdfsdfsdfslkjdfslkjdfslkdfslkjdfslkjldsdfsdfsdfsklkjsd',
        thumb:
          'https://img.yzcdn.cn/public_files/2017/10/24/e5a5a02309a41f9f5def56684808d9ae.jpeg'
      }
    }
  },
  watch: {
    $route (to, from) {
      let isBack = this.$router.isBack //  监听路由变化时的状态为前进还是后退
      if (isBack) {
        console.log('isback')
      } else {
        console.log('noback')
      }
      this.$router.isBack = false
    }
  },
  methods: {
    submitForm () {
      this.axios
        .get('/site/index')
        .then(response => {
          this.msg = response.data.msg
        })
        .catch(function (error) {
          console.log(error)
        })
    },

    formatPrice () {
      return this.goods.price + '橙子'
    },

    customBeforeAppearHook: function (el) {
      console.log('customBeforeAppearHook:')
    },
    customAppearHook: function (el) {
      console.log('customAppearHook:')
      // done()
    },
    customAfterAppearHook: function (el) {
      console.log('customAfterAppearHook:')
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="less" scoped>
@keyframes aslide {
  0% {
    right: -100px;
  }
  100% {
    right: 0px;
  }
}
.van-cell-detail {
  background: green;
  height: 40px;
  overflow: hidden;
  position: relative;
}
.marquee {
  position: absolute;
  right: 0;
  top: 10px;
  background-color: red;
  width: auto;
  height: 20px;
  display: inline-block;
  word-break: keep-all;
  white-space: nowrap;
}

.apper {
  &-active {
    animation: aslide 3s;
    transition: all 3s;
  }
}

.van-cell__right-icon /deep/ {
  align-self: center;
}

.order-panel /deep/ .van-panel__header {
  font-size: 0.2rem;
}
.order-panel /deep/ .van-cell__title {
  flex: 2;
  -webkit-box-flex: 2;
  text-transform: uppercase;
}
.order-panel /deep/ .van-panel__footer {
  font-size: 0.2rem;
}
.order-panel /deep/ .van-panel__footer a {
  color: #42b983;
}
.order-amount {
  text-align: left;
  padding-left: 0.3rem;
  font-size: 0.24rem;
}
.order-amount .price {
  color: #ff6600;
  font-size: 0.4rem;
}
.order-amount small {
  padding-left: 0.1rem;
  font-size: 85%;
  color: #aaa;
}
.order-action /deep/ button {
  display: none;
}
</style>
